package com.levy.contronller.javase.SerializeTest;

/**
 * Created by levy on 2018/7/5.
 */

import java.io.*;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

public class TestObjSerializeAndDeserialize {

    public static void main(String[] args) throws Exception {
        SerializePerson();//序列化Person对象
//        Person p = DeserializePerson();//反序列Perons对象
//        System.out.println(MessageFormat.format("name={0},age={1},sex={2}",
//                p.getName(), p.getAge(), p.getSex()));

//        double f = 0.8;
//        double f2 = 0.7;
//        double f3 = 0.6;
//        System.out.println(0.8-0.7);
//        System.out.println(0.7-0.6);
//        List list = new ArrayList();
//        list.add("a");
//        list.add("b");
//        list.add("c");
//        list.add("d");
//        list.add("e");
//        List list1 = list.subList(0, 3);
//
//        list1.add("f");
//        System.out.println(list1);

    }

    private static void test(String dd, Integer d,Person p) {
        dd = dd +"----YYYYYYYYY";
        d = d + 2;
        p.setAge(20);
    }


    private static void SerializePerson() throws FileNotFoundException, IOException {
        Person person = new Person();
        person.setName("gacl");
        person.setAge(25);
        person.setSex("男");
        // ObjectOutputStream 对象输出流，将Person对象存储到E盘的Person.txt文件中，完成对Person对象的序列化操作
        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File("E:/Person.txt")));
        oo.writeObject(person);
        System.out.println("Person对象序列化成功！");
        oo.close();
    }

    private static Person DeserializePerson() throws Exception, IOException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("E:/Person.txt")));
        Person person = (Person) ois.readObject();
        System.out.println("Person对象反序列化成功！");
        return person;
    }

}